load("@fbcode_macros//build_defs:build_file_migration.bzl", "fbcode_target")
load("@fbcode_macros//build_defs:cpp_benchmark.bzl", "cpp_benchmark")
load("@fbcode_macros//build_defs:cpp_binary.bzl", "cpp_binary")
load("@fbcode_macros//build_defs:cpp_library.bzl", "cpp_library")
load("@fbcode_macros//build_defs:cpp_unittest.bzl", "cpp_unittest")
load("@fbsource//tools/build_defs/dirsync:fb_dirsync_cpp_library.bzl", "fb_dirsync_cpp_library")
load("../../defs.bzl", "folly_xplat_library")

oncall("fbcode_entropy_wardens_folly")

fbcode_target(
    _kind = cpp_unittest,
    name = "atomic_notification_test",
    srcs = [
        "AtomicNotificationTest.cpp",
    ],
    deps = [
        "//folly:optional",
        "//folly/portability:gtest",
        "//folly/synchronization:atomic_notification",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "atomic_ref_test",
    srcs = ["AtomicRefTest.cpp"],
    deps = [
        "//folly/portability:gtest",
        "//folly/synchronization:atomic_ref",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "atomic_struct_test",
    srcs = ["AtomicStructTest.cpp"],
    headers = [],
    deps = [
        "//folly/portability:gtest",
        "//folly/synchronization:atomic_struct",
    ],
)

fbcode_target(
    _kind = cpp_benchmark,
    name = "atomic_util_bench",
    srcs = ["AtomicUtilBench.cpp"],
    deps = [
        "//folly:benchmark",
        "//folly:constexpr_math",
        "//folly/init:init",
        "//folly/lang:aligned",
        "//folly/lang:assume",
        "//folly/lang:keep",
        "//folly/synchronization:atomic_util",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "atomic_util_test",
    srcs = ["AtomicUtilTest.cpp"],
    supports_static_listing = False,
    deps = [
        "//folly:benchmark",
        "//folly:portability",
        "//folly:utility",
        "//folly/portability:gtest",
        "//folly/synchronization:atomic_ref",
        "//folly/synchronization:atomic_util",
    ],
)

fbcode_target(
    _kind = cpp_library,
    name = "barrier",
    headers = ["Barrier.h"],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "barrier_test",
    srcs = ["BarrierTest.cpp"],
    deps = [
        ":barrier",
        "//folly/portability:gtest",
    ],
)

fbcode_target(
    _kind = cpp_benchmark,
    name = "baton_benchmark",
    srcs = ["BatonBenchmark.cpp"],
    deps = [
        ":baton_test_helpers",
        "//folly:benchmark",
        "//folly/synchronization:baton",
        "//folly/synchronization:native_semaphore",
        "//folly/test:deterministic_schedule",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "baton_test",
    srcs = ["BatonTest.cpp"],
    deps = [
        ":baton_test_helpers",
        "//folly/portability:gtest",
        "//folly/synchronization:baton",
        "//folly/test:deterministic_schedule",
    ],
)

fbcode_target(
    _kind = cpp_library,
    name = "baton_test_helpers",
    headers = ["BatonTestHelpers.h"],
    exported_deps = [
        "//folly/portability:gtest",
        "//folly/synchronization:baton",
        "//folly/test:deterministic_schedule",
    ],
)

fbcode_target(
    _kind = cpp_binary,
    name = "call_once_benchmark",
    srcs = ["CallOnceBenchmark.cpp"],
    headers = [],
    deps = [
        "//folly:benchmark",
        "//folly/lang:keep",
        "//folly/synchronization:call_once",
    ],
    external_deps = [
        "glog",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "call_once_test",
    srcs = ["CallOnceTest.cpp"],
    headers = [],
    deps = [
        "//folly:traits",
        "//folly/portability:gtest",
        "//folly/synchronization:call_once",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "delayed_init_test",
    srcs = ["DelayedInitTest.cpp"],
    headers = [],
    deps = [
        "fbsource//third-party/fmt:fmt",
        ":barrier",
        "//folly/portability:gtest",
        "//folly/synchronization:delayed_init",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "distributed_mutex_test",
    srcs = [
        "DistributedMutexTest.cpp",
    ],
    labels = [
        "heavyweight",
        "slow",
    ],
    deps = [
        "//folly:map_util",
        "//folly:synchronized",
        "//folly/container:array",
        "//folly/container:foreach",
        "//folly/lang:customization_point",
        "//folly/lang:keep",
        "//folly/portability:gtest",
        "//folly/synchronization:baton",
        "//folly/synchronization:distributed_mutex",
        "//folly/system:hardware_concurrency",
        "//folly/test:deterministic_schedule",
        "//folly/test:test_utils",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "hazptr_test",
    srcs = ["HazptrTest.cpp"],
    deps = [
        ":barrier",
        "//folly:singleton",
        "//folly/portability:gflags",
        "//folly/portability:gtest",
        "//folly/synchronization:hazptr",
        "//folly/synchronization:hazptr_thread_pool_executor",
        "//folly/synchronization/example:hazptr_lock_free_lifo",
        "//folly/synchronization/example:hazptr_swmr_set",
        "//folly/synchronization/example:hazptr_wide_cas",
        "//folly/test:deterministic_schedule",
    ],
)

fbcode_target(
    _kind = cpp_benchmark,
    name = "hazptr_bench",
    srcs = ["HazptrBench.cpp"],
    deps = [
        "//folly:benchmark",
        "//folly:spin_lock",
        "//folly/concurrency:atomic_shared_ptr",
        "//folly/concurrency:core_cached_shared_ptr",
        "//folly/concurrency/memory:atomic_read_mostly_main_ptr",
        "//folly/concurrency/memory:read_mostly_shared_ptr",
        "//folly/container:enumerate",
        "//folly/container:f14_hash",
        "//folly/portability:gflags",
        "//folly/synchronization:hazptr",
        "//folly/synchronization:rcu",
        "//folly/synchronization:rw_spin_lock",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "latch_test",
    srcs = ["LatchTest.cpp"],
    deps = [
        "//folly/portability:gtest",
        "//folly/synchronization:latch",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "lifo_sem_test",
    srcs = ["LifoSemTests.cpp"],
    headers = [],
    allocator = "jemalloc_debug",
    deps = [
        "//folly:random",
        "//folly/portability:asm",
        "//folly/portability:gflags",
        "//folly/portability:gtest",
        "//folly/synchronization:lifo_sem",
        "//folly/synchronization:native_semaphore",
        "//folly/test:deterministic_schedule",
    ],
)

fbcode_target(
    _kind = cpp_benchmark,
    name = "lifo_sem_bench",
    srcs = ["LifoSemBench.cpp"],
    headers = [],
    deps = [
        "//folly:benchmark",
        "//folly/portability:asm",
        "//folly/synchronization:lifo_sem",
        "//folly/synchronization:native_semaphore",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "lock_test",
    srcs = ["LockTest.cpp"],
    supports_static_listing = False,
    deps = [
        "//folly/portability:gtest",
        "//folly/synchronization:lock",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "native_semaphore_test",
    srcs = ["NativeSemaphoreTest.cpp"],
    deps = [
        "//folly/portability:gtest",
        "//folly/synchronization:native_semaphore",
    ],
)

fbcode_target(
    _kind = cpp_binary,
    name = "parking_lot_benchmark",
    srcs = ["ParkingLotBenchmark.cpp"],
    deps = [
        ":barrier",
        "//folly:benchmark",
        "//folly/detail:futex",
        "//folly/synchronization:parking_lot",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "parking_lot_test",
    srcs = ["ParkingLotTest.cpp"],
    deps = [
        "//folly/portability:gtest",
        "//folly/synchronization:baton",
        "//folly/synchronization:parking_lot",
    ],
)

fbcode_target(
    _kind = cpp_binary,
    name = "rcu_bench",
    srcs = ["RcuBench.cpp"],
    headers = [],
    deps = [
        "//folly:benchmark",
        "//folly/synchronization:rcu",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "rcu_test",
    srcs = ["RcuTest.cpp"],
    deps = [
        ":barrier",
        "//folly:benchmark",
        "//folly:random",
        "//folly/portability:gflags",
        "//folly/portability:gtest",
        "//folly/synchronization:rcu",
        "//folly/synchronization:relaxed_atomic",
    ],
    external_deps = [
        "glog",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "relaxed_atomic_test",
    srcs = ["RelaxedAtomicTest.cpp"],
    headers = [],
    deps = [
        "//folly/portability:gtest",
        "//folly/synchronization:atomic_util",
        "//folly/synchronization:relaxed_atomic",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "rw_spin_lock_test",
    srcs = ["RWSpinLockTest.cpp"],
    headers = [],
    deps = [
        "//folly/portability:gflags",
        "//folly/portability:gtest",
        "//folly/portability:unistd",
        "//folly/synchronization:rw_spin_lock",
    ],
    external_deps = [
        "glog",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "saturating_semaphore_test",
    srcs = ["SaturatingSemaphoreTest.cpp"],
    deps = [
        "//folly/portability:gtest",
        "//folly/synchronization:saturating_semaphore",
        "//folly/test:deterministic_schedule",
    ],
)

fbcode_target(
    _kind = cpp_library,
    name = "semaphore",
    headers = ["Semaphore.h"],
    exported_deps = [
        "//folly:optional",
        "//folly:scope_guard",
        "//folly/lang:exception",
    ],
    external_deps = ["boost"],
    exported_external_deps = [
        "boost",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "semaphore_test",
    srcs = ["SemaphoreTest.cpp"],
    deps = [
        ":barrier",
        ":semaphore",
        "//folly/portability:gtest",
        "//folly/portability:sys_mman",
        "//folly/synchronization:latch",
    ],
    external_deps = [
        "glog",
    ],
)

fbcode_target(
    _kind = cpp_benchmark,
    name = "small_locks_benchmark",
    srcs = ["SmallLocksBenchmark.cpp"],
    deps = [
        "fbsource//third-party/fmt:fmt",
        "//folly:benchmark",
        "//folly:shared_mutex",
        "//folly/lang:aligned",
        "//folly/synchronization:distributed_mutex",
        "//folly/synchronization:flat_combining",
        "//folly/synchronization:rw_spin_lock",
        "//folly/synchronization:small_locks",
        "//folly/system:hardware_concurrency",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "small_locks_test",
    srcs = ["SmallLocksTest.cpp"],
    headers = [],
    deps = [
        "//folly:random",
        "//folly/portability:asm",
        "//folly/portability:gflags",
        "//folly/portability:gmock",
        "//folly/portability:gtest",
        "//folly/portability:pthread",
        "//folly/portability:unistd",
        "//folly/synchronization:small_locks",
        "//folly/system:hardware_concurrency",
        "//folly/test:test_utils",
    ],
    external_deps = [
        "glog",
    ],
)

fbcode_target(
    _kind = cpp_library,
    name = "thread_cached_epoch_bench_util",
    headers = ["ThreadCachedEpochBench.h"],
    exported_deps = [
        "//folly:benchmark",
        "//folly/synchronization/detail:rcu-detail",
    ],
)

fbcode_target(
    _kind = cpp_binary,
    name = "thread_cached_readers_bench",
    srcs = ["ThreadCachedReadersBench.cpp"],
    headers = [],
    deps = [
        ":thread_cached_epoch_bench_util",
        "//folly:benchmark",
        "//folly/synchronization/detail:rcu-detail",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "thread_cached_readers_test",
    srcs = ["ThreadCachedReadersTest.cpp"],
    headers = [],
    deps = [
        "//folly:thread_local",
        "//folly/portability:gtest",
        "//folly/synchronization/detail:rcu-detail",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "throttled_lifo_sem_test",
    srcs = [
        "ThrottledLifoSemTest.cpp",
    ],
    deps = [
        "//folly:benchmark",
        "//folly:random",
        "//folly/portability:gtest",
        "//folly/synchronization:saturating_semaphore",
        "//folly/synchronization:throttled_lifo_sem",
    ],
)

fb_dirsync_cpp_library(
    name = "flat_combining_examples",
    headers = ["FlatCombiningExamples.h"],
    xplat_impl = folly_xplat_library,
    exported_deps = [
        "//folly/synchronization:baton",
        "//folly/synchronization:flat_combining",
    ],
)

fb_dirsync_cpp_library(
    name = "flat_combining_test_helpers",
    headers = ["FlatCombiningTestHelpers.h"],
    xplat_impl = folly_xplat_library,
    exported_deps = [
        "//folly:benchmark",
        "//folly/synchronization/test:flat_combining_examples",
    ],
    external_deps = ["glog"],
    exported_external_deps = [
        "glog",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "flat_combining_benchmark",
    srcs = ["FlatCombiningBenchmark.cpp"],
    deps = [
        ":flat_combining_test_helpers",
        "//folly:benchmark",
        "//folly/portability:gtest",
        "//folly/system:hardware_concurrency",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "flat_combining_test",
    srcs = ["FlatCombiningTest.cpp"],
    supports_static_listing = False,
    deps = [
        "//folly/portability:gtest",
        "//folly/synchronization/test:flat_combining_test_helpers",
    ],
    external_deps = [
        "glog",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "event_count_test",
    srcs = ["EventCountTest.cpp"],
    headers = [],
    deps = [
        "//folly:random",
        "//folly/portability:gtest",
        "//folly/synchronization:event_count",
    ],
    external_deps = [
        "glog",
    ],
)

fbcode_target(
    _kind = cpp_unittest,
    name = "striped_throttled_lifo_sem_test",
    srcs = ["StripedThrottledLifoSemTest.cpp"],
    headers = [],
    deps = [
        "//folly:random",
        "//folly:scope_guard",
        "//folly/portability:gtest",
        "//folly/synchronization:striped_throttled_lifo_sem",
    ],
)
